Interfacing LORA SX1278 Module With Arduino

Long-distance communication (or constant data transmissions) has become essential to modern industries, the medical sector, and even the residential sector. These data include the status/outputs of sensors, operation logs of machines, images or videos, scheduled events, etc. Transferring these data between machines via wired or wireless medium without human input is called Machine-to-Machine communication (M2M). The same communication using a cloud platform instead of point-to-point becomes IoT. Realizing the growing demand for faster, more secure, and more efficient communication, technologies that enable long-range wireless communication were developed. Of many, “LoRa” stood out by satisfying the need for low power consumption, higher communication range, interference immunity, mobility, and energy efficiency. It was designed for sensor data transmission at low speeds (around 20-50 Kbps).

In this article, we will interface Arduino Nano and a transponder module called LoRa SX1278 (which utilizes the patented “LoRa” modulation technique). After interfacing the module, we will also learn to transmit data between two LoRa sensor nodes. For example, we will use the DHT11 sensor to transmit humidity and temperature data.

After completing this article, you will be able to:

  1. Interface the LoRa-02 module with Arduino Nano.
  2. Transmit sensor data between LoRa nodes.
  3. Display the readings on the LCD.

Introduction to “LoRa”:

“LoRa,” meaning “Long Ranged,” is a well-known radio communication method. LoRa in itself is a physical layer protocol that is derived from Chirp Spread Spectrum (CSS). CSS is a wideband linear frequency modulation in which carrier frequency varies for the defined extent of time. A chirp is a sinusoidal signal whose frequency increases or decreases over time (often with a polynomial relationship between time and frequency). Due to this, CSS is ideal for applications requiring low power usage with lower data rates (<1 Mbit/s), longer ranges, and when devices moving at high speeds are part of your network.

The “LoRa module” supports different ISM band frequencies, namely 868MHz (Europe), 915MHz (North America), and 433MHz (Asia), and encodes information on radio waves using chirp pulses. So, we can conclude that LoRa targets key Internet of Things (IoT) requirements such as bidirectional communication, end-to-end security, mobility, and localization services.

lora sx1278

Figure 1: LoRa SX1278 Module

This article will use a specific LoRa SX1278 module consisting of a “Ra-02” chip from AI-Thinker. This chip supports the ISM band of range 410-525MHz, a Power amplifier (PA) of +18dBm, and LoRa/FSK/OOK modulation techniques. The features and Specification of the whole package are given as follows:

Features of SX1278 LoRa:

  • works in ISM bands (Industrial Standard Medical band)
  • Half-duplex SPI communication
  • Low powered consumption 
  • High-range coverage (~10Km)
  • Operates on low bandwidth
  • Supports Preamble detection
  • excellent blocking and interference immunity
  • Built-in temperature sensor and battery indicator.
  • Built-in bit synchronizer for clock recovery

Specification:

  • Module Model: Ra-02
  • Package: SMD-16
  • Size/Dim: 17*16*(3.2 ± 0.1) mm 
  • Programmable bit rate up to 300 kbps
  • Frequency Range: 410 MHz – 525 MHz
  • Operating temperature: -30℃ to 85℃
  • Power Supply: 2.5 ~ 3.7V (Typically : 3.3V)
  • industry-leading 168dB max Link budget
  • High sensitivity: down to -148 dBm
  • +20 dBm (i.e ~ 100 mW) RF transmit power
  • can use FSK, GFSK, MSK, GMSK, OOK, and LoRa (default) modulation
  • Low RX current of 9.9 mA, 200 nA register retention
  • Bullet-proof front end: IIP3 = -11 dBm
  • 127dB RSSI Dynamic Range

Components Required

Arduino Nano x 2

LoRa-2 SX1278 x 2

DHT11 (Hum & Temp) x 1

16X2 – I2C LCD display x 2

Interfacing Sx1278 with Nano:

The table below describes the wiring between I2C_LCD, LoRa, and Nano for the transmitter and receiver nodes.

As the figures below demonstrate, the I2C_LCD has its VCC & GND pin connected to 5V & ground, whereas its SDA & SCL pin to analog pins A4 & A5 of Nano.

For LoRa and Nano interfacing, the following is given below:

LoRa-02 SX1278 NANO pins
VCC (3.6V max) 3.3V
GND GND
SCK (SPI clock) D13
DIO0 (Digital I/O) D2
RST (Reset) D9
NSS (Chip select) D10
MOSI (SPI data input) D11
MISO (SPI data output) D12

Transmitter circuit of lora sx1278

Use 3.3V of Arduino Nano to connect it to the VCC pin of the LoRa module. Connect all the GND pins to GND. Connect the RST pin to D9 and DIO0 to D2 of Arduino. As shown in the circuit diagram above, connect the SPI Pins NSS, MOSI, MISO, and SCK to Arduino D10, D11, D12, and D13 Arduino. Then, the VCC, DATA & GND pins of the DHT11 (humidity & temperature) sensor are connected to the 5V, D3, and GND pins of Nano, respectively, as shown above.

receiver circuit of lora sx1278

Use 3.3V of Arduino Nano to connect it to the VCC pin of the LoRa module. Connect all the GND pins to GND. Connect the RST pin to D9 and DIO0 to D2 of Arduino. As shown in the circuit diagram above, connect the SPI Pins NSS, MOSI, MISO, and SCK to Arduino D10, D11, D12, and D13 Arduino. Then connect the D3 pin of nano to the cathode of LED and then to gnd via a 470Ω resistor as shown.

How to transmit Sensor Data:

Firstly, we require two libraries to operate the LoRa-02 SX1278 module via the Nano, namely <SPI.h> and <LoRa.h>. The “SPI.h” library is responsible for serial communication between module and nano, whereas “LoRa.h” is responsible for transmitting/Receiving operations.[Note: This “LoRa.h” library allows you to send data to any radios in range with the same radio parameters. All data are broadcasted without any addressing.]. We are using DHT11(temperature & humidity sensor) for the sensor. So the <DHT.h> library is required to extract the temperature and humidity data captured by the DHT11 sensor.

After successfully interfacing all the hardware as instructed, the step-by-step explanation of the code for sensor data reading and transmission process is given below:

Software Code

Transmitter Side Code

Including necessary libraries:

Three libraries, DHT.h, SPI.h, and LoRa.h, are included for sensor data generation/reading. They serially transfer that data from Nano to the LoRa module and then transmit it.

Defining important parameters:

Here, the incoming data from DHT11 is assigned to digital pin D3 of nano. We also have to specify the sensor model type while initializing the sensor. Then, two variables, humidity and temperature data, are required.

Initialize Setup Function:

Here, we initialize the LoRa library with a 433MHz frequency using LoRa.begin(). This function also scans whether a message has been sent. If not, it displays” Starting LoRa failed!”

Read and transmit sensor Data: 

Read the temperature and humidity data using “dht” objects and store them into respective variables. Then, transmit them using the LoRa.print() function. The transmitted message ends with a “*” character, which the receiver uses to break the combined serial characters into a meaningful message.

After the transmission is done, a step explanation of the code performing the data reception process is given below:

Receiver Side Code

Initialize the necessary libraries and parameters:

We include the SPI.h and LoRa.h libraries for serial communication and LoRa module operations. Then a String type variable (inString) captures the incoming character and merges them into one string. The counter is the count no of captured characters.

Initialize the Setup function:

Here, we initialize the LoRa library with a 433MHz frequency using LoRa.begin(). This function scans whether a message has been sent. If not, it displays “Starting LoRa failed!”

Void loop:

Here, we will check if a packet has been received using “LoRa.parsePacket().” This function returns the packet size in bytes or 0 if no packet was received. Then, read the characters and append them to a string variable (inString). Then, display the message/combined data in the serial monitor. If the “*” character is received, it indicates the end of the message.

Complete Code:

Displaying the Sensor Data in LCD

The transfer of sensor data has been modified and displayed in LCD. The code is as follows:

Transmitter Code:

Receiver Code:

author prototype of lora interfacing

Figure 4: Author Prototype of LoRa Interfacing Transmitter Circuit

Figure 5: Author Prototype of LoRa Interfacing Receiver Circuit

One Thought to “Interfacing LORA SX1278 Module With Arduino”

  1. Samuel Adham

    it’s a really great project , I am working at the same project idea but i use the lora module to make the parent’s and child’s bracelet that able to communicate with each other wirelessly in order to make the parents always connected to the child so prevent them from kidnapping so i was wondering what is your opinion at this project and also i want to know how to add lora sx1278 to the proteus to be able to test the project before the physical implementation…Thanks for your time.

Leave a Comment